package com.example.androidtraining_ahut2020;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;


import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class MainActivityDay10ListViewApp extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        final String[] cities = new String[]{"兰州", "北京", "上海"};
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_day10_list);

        ListView listView = (ListView) findViewById(R.id.List);
        listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, cities));
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                Toast.makeText(MainActivityDay10ListViewApp.this, arg2, Toast.LENGTH_SHORT).show();

            }


        });

    }
}